use hierarchy with cmake. (#807)
authortsteven4 <13596209+tsteven4@users.noreply.github.com>
Sun, 2 Jan 2022 23:51:03 +0000 (16:51 -0700)
committerGitHub <noreply@github.com>
Sun, 2 Jan 2022 23:51:03 +0000 (16:51 -0700)
* use hierarchy with cmake.

* adjust cmake test script for hierarchy.

the default target with cmake builds both the CLI and the GUI.
alternatively, "cmake --build . --target gpsbabel" to build just the
CLI or "cmake --build . --target GPSBabelFE|gpsbabelfe to build just
the GUI.

* detect attempts to generate a build system from a subdirectory.

* fix shellcheck issues.

13 files changed:
.github/workflows/fedora.yml
.github/workflows/ubuntu.yml
CMakeLists.txt
GPSBabel.pro
build_and_test [deleted file]
gbversion.cmake
gui/CMakeLists.txt
tools/build_and_test.sh [new file with mode: 0755]
tools/build_and_test_cmake [deleted file]
tools/build_and_test_cmake.sh [new file with mode: 0755]
tools/build_extra_tests [deleted file]
tools/build_extra_tests.sh [new file with mode: 0755]
tools/make_windows_release.ps1

index b4e517158839d315f7ffaedce9e8a948bf53e11a..41e4d6e044ae6d639334f2228dd4c272303b8e07 100644 (file)
@@ -30,4 +30,4 @@ jobs:
 
     - name: build_and_test
       run: |
-        ./build_and_test
+        ./tools/build_and_test.sh
index b4ecbf5ab4c5f7383dd7b1c028d86196c9ddf301..eac0f10bb3aa64339179db637b85e0393e48d871 100644 (file)
@@ -24,7 +24,7 @@ jobs:
 
     - name: build_and_test
       run: |
-        ./build_and_test
+        ./tools/build_and_test.sh
 
   cmake:
     name: cmake Build
@@ -40,7 +40,7 @@ jobs:
 
     - name: build_and_test
       run: |
-        ./tools/build_and_test_cmake
+        ./tools/build_and_test_cmake.sh
 
   qtio_gcc:
     name: qtio gcc Build
@@ -57,7 +57,7 @@ jobs:
     - name: build_and_test
       run: |
         . /opt/qtio.env
-        ./build_and_test
+        ./tools/build_and_test.sh
 
   qtio_clang:
     name: qtio clang Build
@@ -75,7 +75,7 @@ jobs:
     - name: build_and_test
       run: |
         . /opt/qtio.env
-        ./build_and_test
+        ./tools/build_and_test.sh
 
   advanced:
     name: advanced Build
@@ -91,7 +91,7 @@ jobs:
 
     - name: build_extra_tests
       run: |
-        ./tools/build_extra_tests
+        ./tools/build_extra_tests.sh
 
   coverage:
     name: coverage Build
index fa6d0dfaff9af5b601d1b074a96fc8403f036be9..fce1a63b575dd0f81704dcb95b681b258434bb4d 100644 (file)
@@ -1,12 +1,20 @@
 cmake_minimum_required(VERSION 3.11)
 
 include(gbversion.cmake)
-configure_file(gbversion.h.in gbversion.h @ONLY NEWLINE_STYLE LF)
 project(gpsbabel LANGUAGES C CXX VERSION ${GB.VERSION})
 
 set(CMAKE_CXX_STANDARD 17)
 set(CMAKE_CXX_STANDARD_REQUIRED True)
 
+# Do this after we set up common variables but before creating other
+# variables that will be inherited.
+add_subdirectory(gui)
+
+# FIXME: When we rearrange the project directory structure everything
+# below here should be in it's own CMakeList.txt
+
+configure_file(gbversion.h.in gbversion.h @ONLY NEWLINE_STYLE LF)
+
 # Find includes in corresponding build directories
 set(CMAKE_INCLUDE_CURRENT_DIR ON)
 # Handle the Qt rcc code generator automatically
@@ -249,7 +257,6 @@ set(HEADERS
   gbfile.h
   gbser.h
   gbser_private.h
-  gbversion.h
   geojson.h
   ggv_bin.h
   globalsat_sport.h
index dfb828529cc504ec3ca56d4e675bc389b16ec587..0136041311c15b2511d718f41e18d147a721827f 100644 (file)
@@ -221,7 +221,6 @@ HEADERS =  \
   gbfile.h \
   gbser.h \
   gbser_private.h \
-  gbversion.h \
   geojson.h \
   ggv_bin.h \
   globalsat_sport.h \
diff --git a/build_and_test b/build_and_test
deleted file mode 100755 (executable)
index 6d540e5..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-#!/bin/bash -ex
-#
-# this script is triggered by SCM changes and is run on the build server.
-# output is conditionally mailed to gpsbabel-code.
-#
-# echo some system info to log
-uname -a
-if [ -e /etc/system-release ]; then
-       cat /etc/system-release
-fi
-if [ -e /etc/os-release ]; then
-       cat /etc/os-release
-fi
-git --no-pager log -n 1
-# build and test keeping output within the pwd.
-export GBTEMP=$(pwd)/gbtemp
-mkdir -p $GBTEMP
-qmake WEB=$(pwd)/gpsbabel_docdir
-# As of 2018-10, all the virtualized travis build images are two cores per:
-# https://docs.travis-ci.com/user/reference/overview/
-# We'll be slightly abusive on CPU knowing that I/O is virtualized.
-make toolinfo
-make clean
-make -j 3
-make -j 3 unix-gui
-make gpsbabel.html
-make gpsbabel.pdf
-make gpsbabel.org
-make check
-# test for mangled encoding of command line arguments
-./test_encoding_latin1
-./test_encoding_utf8
-#make torture
-make -k -j2 check-vtesto
-# eat the verbose output from test-all, including crash.output
-# this is a bit risky, if test-all generates an error we won't see what happened.
-echo "test-all in progress... (read/write test between all possible formats)"
-(LIBC_FATAL_STDERR_=1; export LIBC_FATAL_STDERR_; ./test-all -s -r reference/expertgps.gpx >/dev/null 2>&1)
-# summarize the test-all results, and generate an error if a fatal error was
-# detected by test-all.
-./test-all -J
index 0195e4296da0c1d398be4f14387a19a5c85186fb..dc6f1a55f437eaf90cf166e54bd7d88e38f15c8d 100644 (file)
@@ -1,10 +1,8 @@
 # Use GB variable to express ownership intention and avoid conflict with
 # documented and undocumented cmake variables.
 
-# Until we do a hierarchical build the build directory for gpsbabel and
-# the build directory for GPSBabelFE are independent.  Only the source
-# directories have a known relationship.  Including this pri file from the
-# source tree will generate the version file in the current build directory.
+# Including this pri file from ${CMAKE_SOURCE_DIR} will generate the version
+# file in the current build directory, i.e. ${CMAKE_CURRENT_BINARY_DIR}.
 
 # Note some of these variables are also used in the gui to generate setup.iss.
 # Note some of these variables are also used in the cli to generate documents.
index bc62bc5af0fa11a17bf6a5eca978627f1f161e51..ad42f3b8372a456350b1334a1d467328992fac5b 100644 (file)
@@ -1,12 +1,9 @@
-cmake_minimum_required(VERSION 3.11)
+if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
+  message(FATAL_ERROR "Please use CMakeLists.txt in the project root directory to generate a build system.")
+endif()
 
-include(../gbversion.cmake)
-configure_file(../gbversion.h.in gbversion.h @ONLY NEWLINE_STYLE LF)
+configure_file(${CMAKE_SOURCE_DIR}/gbversion.h.in gbversion.h @ONLY NEWLINE_STYLE LF)
 configure_file(setup.iss.in setup.iss @ONLY NEWLINE_STYLE CRLF)
-project(gpsbabelfe LANGUAGES CXX VERSION ${GB.VERSION})
-
-set(CMAKE_CXX_STANDARD 17)
-set(CMAKE_CXX_STANDARD_REQUIRED True)
 
 # Find includes in corresponding build directories
 set(CMAKE_INCLUDE_CURRENT_DIR ON)
diff --git a/tools/build_and_test.sh b/tools/build_and_test.sh
new file mode 100755 (executable)
index 0000000..9993e7b
--- /dev/null
@@ -0,0 +1,41 @@
+#!/bin/bash -ex
+#
+# this script is triggered by SCM changes and is run on the build server.
+# output is conditionally mailed to gpsbabel-code.
+#
+# echo some system info to log
+uname -a
+if [ -e /etc/system-release ]; then
+       cat /etc/system-release
+fi
+if [ -e /etc/os-release ]; then
+       cat /etc/os-release
+fi
+git --no-pager log -n 1
+# build and test keeping output within the pwd.
+export GBTEMP=$(pwd)/gbtemp
+mkdir -p "$GBTEMP"
+qmake WEB="$(pwd)/gpsbabel_docdir"
+# As of 2018-10, all the virtualized travis build images are two cores per:
+# https://docs.travis-ci.com/user/reference/overview/
+# We'll be slightly abusive on CPU knowing that I/O is virtualized.
+make toolinfo
+make clean
+make -j 3
+make -j 3 unix-gui
+make gpsbabel.html
+make gpsbabel.pdf
+make gpsbabel.org
+make check
+# test for mangled encoding of command line arguments
+./test_encoding_latin1
+./test_encoding_utf8
+#make torture
+make -k -j2 check-vtesto
+# eat the verbose output from test-all, including crash.output
+# this is a bit risky, if test-all generates an error we won't see what happened.
+echo "test-all in progress... (read/write test between all possible formats)"
+(LIBC_FATAL_STDERR_=1; export LIBC_FATAL_STDERR_; ./test-all -s -r reference/expertgps.gpx >/dev/null 2>&1)
+# summarize the test-all results, and generate an error if a fatal error was
+# detected by test-all.
+./test-all -J
diff --git a/tools/build_and_test_cmake b/tools/build_and_test_cmake
deleted file mode 100755 (executable)
index 717e91d..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-#!/bin/bash -ex
-#
-# this script is triggered by SCM changes and is run on the build server.
-# output is conditionally mailed to gpsbabel-code.
-#
-# echo some system info to log
-uname -a
-if [ -e /etc/system-release ]; then
-       cat /etc/system-release
-fi
-if [ -e /etc/os-release ]; then
-       cat /etc/os-release
-fi
-git --no-pager log -n 1
-# build and test keeping output within the pwd.
-export GBTEMP=$(pwd)/gbtemp
-mkdir -p $GBTEMP
-cmake . -G Ninja -DCMAKE_BUILD_TYPE=Release -DWEB=$(pwd)/gpsbabel_docdir
-# As of 2018-10, all the virtualized travis build images are two cores per:
-# https://docs.travis-ci.com/user/reference/overview/
-# We'll be slightly abusive on CPU knowing that I/O is virtualized.
-#make toolinfo
-cmake --build . --target clean
-cmake --build .
-cmake --build . --target gpsbabel.html
-cmake --build . --target gpsbabel.pdf
-cmake --build . --target gpsbabel.org
-cmake --build . --target check
-#make -j 3 unix-gui
-# FIXME: use hierarchical build
-pushd gui
-cmake . -G Ninja
-cmake --build .
-popd
-# test for mangled encoding of command line arguments
-./test_encoding_latin1
-./test_encoding_utf8
-#make torture
-cmake --build . --target check-vtesto
-# eat the verbose output from test-all, including crash.output
-# this is a bit risky, if test-all generates an error we won't see what happened.
-echo "test-all in progress... (read/write test between all possible formats)"
-(LIBC_FATAL_STDERR_=1; export LIBC_FATAL_STDERR_; ./test-all -s -r reference/expertgps.gpx >/dev/null 2>&1)
-# summarize the test-all results, and generate an error if a fatal error was
-# detected by test-all.
-./test-all -J
diff --git a/tools/build_and_test_cmake.sh b/tools/build_and_test_cmake.sh
new file mode 100755 (executable)
index 0000000..59d49b6
--- /dev/null
@@ -0,0 +1,41 @@
+#!/bin/bash -ex
+#
+# this script is triggered by SCM changes and is run on the build server.
+# output is conditionally mailed to gpsbabel-code.
+#
+# echo some system info to log
+uname -a
+if [ -e /etc/system-release ]; then
+       cat /etc/system-release
+fi
+if [ -e /etc/os-release ]; then
+       cat /etc/os-release
+fi
+git --no-pager log -n 1
+# build and test keeping output within the pwd.
+export GBTEMP=$(pwd)/gbtemp
+mkdir -p "$GBTEMP"
+cmake . -G Ninja -DCMAKE_BUILD_TYPE=Release -DWEB="$(pwd)/gpsbabel_docdir"
+# As of 2018-10, all the virtualized travis build images are two cores per:
+# https://docs.travis-ci.com/user/reference/overview/
+# We'll be slightly abusive on CPU knowing that I/O is virtualized.
+#make toolinfo
+cmake --build . --target clean
+cmake --build . --target gpsbabel
+cmake --build . --target gpsbabel.html
+cmake --build . --target gpsbabel.pdf
+cmake --build . --target gpsbabel.org
+cmake --build . --target check
+cmake --build . --target gpsbabelfe
+# test for mangled encoding of command line arguments
+./test_encoding_latin1
+./test_encoding_utf8
+#make torture
+cmake --build . --target check-vtesto
+# eat the verbose output from test-all, including crash.output
+# this is a bit risky, if test-all generates an error we won't see what happened.
+echo "test-all in progress... (read/write test between all possible formats)"
+(LIBC_FATAL_STDERR_=1; export LIBC_FATAL_STDERR_; ./test-all -s -r reference/expertgps.gpx >/dev/null 2>&1)
+# summarize the test-all results, and generate an error if a fatal error was
+# detected by test-all.
+./test-all -J
diff --git a/tools/build_extra_tests b/tools/build_extra_tests
deleted file mode 100755 (executable)
index 05ad8f5..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-#!/bin/bash -ex
-#
-# this script is triggered by SCM changes and is run on the build server.
-# output is conditionally mailed to gpsbabel-code.
-#
-
-# echo some system info to log
-uname -a
-if [ -e /etc/system-release ]; then
-       cat /etc/system-release
-fi
-if [ -e /etc/os-release ]; then
-       cat /etc/os-release
-fi
-git --no-pager log -n 1
-
-# build and test keeping output within the pwd.
-export GBTEMP=$(mktemp -d -p $(pwd) GBTEMPXXXX)
-
-#note that debug will also enable assertions.
-qmake "CONFIG+=debug sanitizer sanitize_address"
-make clean
-make -j 3
-make check
-
-qmake "CONFIG+=debug sanitizer sanitize_undefined"
-make clean
-make -j 3
-make check
-
-export CLAZY_CHECKS=level0,level1,no-non-pod-global-static,no-qstring-ref
-qmake -spec linux-clang "CONFIG+=debug" "QMAKE_CXX=clazy"
-make clean
-make -j 3 2>&1 | tee clazy.log
-if grep -- '-Wclazy' clazy.log; then
-  exit 1
-else
-  exit 0
-fi
-
diff --git a/tools/build_extra_tests.sh b/tools/build_extra_tests.sh
new file mode 100755 (executable)
index 0000000..05ad8f5
--- /dev/null
@@ -0,0 +1,40 @@
+#!/bin/bash -ex
+#
+# this script is triggered by SCM changes and is run on the build server.
+# output is conditionally mailed to gpsbabel-code.
+#
+
+# echo some system info to log
+uname -a
+if [ -e /etc/system-release ]; then
+       cat /etc/system-release
+fi
+if [ -e /etc/os-release ]; then
+       cat /etc/os-release
+fi
+git --no-pager log -n 1
+
+# build and test keeping output within the pwd.
+export GBTEMP=$(mktemp -d -p $(pwd) GBTEMPXXXX)
+
+#note that debug will also enable assertions.
+qmake "CONFIG+=debug sanitizer sanitize_address"
+make clean
+make -j 3
+make check
+
+qmake "CONFIG+=debug sanitizer sanitize_undefined"
+make clean
+make -j 3
+make check
+
+export CLAZY_CHECKS=level0,level1,no-non-pod-global-static,no-qstring-ref
+qmake -spec linux-clang "CONFIG+=debug" "QMAKE_CXX=clazy"
+make clean
+make -j 3 2>&1 | tee clazy.log
+if grep -- '-Wclazy' clazy.log; then
+  exit 1
+else
+  exit 0
+fi
+
index 32e8a0f5f97c400833be7d35e60a5a6c712df80f..50ed936b9528161c7a5412af2eda29d0f70722e9 100755 (executable)
@@ -31,7 +31,11 @@ $ErrorActionPreference = "Stop"
 Get-Item tools/make_windows_release.ps1 -ErrorAction Stop | Out-Null\r
 $gpsbabel_src_dir = "$Pwd"\r
 $gpsbabel_build_dir = "$($gpsbabel_src_dir)\..\$($gpsbabel_build_dir_name)"\r
-$gui_build_dir = "$($gpsbabel_src_dir)\$($gui_build_dir_name)"\r
+if ( "$flow" -eq "cmake" ) {\r
+  $gui_build_dir = "$($gpsbabel_build_dir)"\r
+} else {\r
+  $gui_build_dir = "$($gpsbabel_src_dir)\$($gui_build_dir_name)"\r
+}\r
 if ( "$flow" -eq "msbuild" ) {\r
     # translate target architecture to Platform property value.\r
     switch ($arch) {\r
@@ -71,26 +75,27 @@ if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) }
 # copy GPSBabel.exe for use by test_script\r
 Remove-Item "$($gpsbabel_src_dir)\release" -Recurse -ErrorAction Ignore\r
 New-Item "$($gpsbabel_src_dir)\release" -type directory -Force | Out-Null\r
-Copy-Item release\GPSBabel.exe "$($gpsbabel_src_dir)\release\GPSBabel.exe"\r
-Set-Location "$($gpsbabel_src_dir)"\r
-# make sure we are staring with a clean build directory\r
-Remove-Item "$($gui_build_dir)" -Recurse -ErrorAction Ignore\r
-New-Item "$($gui_build_dir)" -type directory -Force | Out-Null\r
-Set-Location "$($gui_build_dir)"\r
-switch ($flow) {\r
-    "mingw" { qmake "$($gpsbabel_src_dir)\gui\app.pro" -spec "win32-g++" }\r
-    "msbuild" { qmake -tp vc "$($gpsbabel_src_dir)\gui\app.pro" }\r
-    "nmake" { qmake "$($gpsbabel_src_dir)\gui\app.pro" -spec "win32-msvc" }\r
-    "cmake" { cmake -G "Ninja" -DCMAKE_BUILD_TYPE:STRING:="Release" -DCMAKE_PREFIX_PATH:PATH="$($CMAKE_PREFIX_PATH)" -DCMAKE_RUNTIME_OUTPUT_DIRECTORY:PATH="$($gui_build_dir)\release" "$($gpsbabel_src_dir)\gui" }\r
-}\r
-if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) }\r
-switch ($flow) {\r
-    "mingw" { ming32-make }\r
-    "msbuild" { msbuild GPSBabelFE.vcxproj -property:Configuration=Release -property:Platform=$platform }\r
-    "nmake" { nmake /NOLOGO }\r
-    "cmake" { cmake --build . }\r
+Copy-Item "$($gpsbabel_build_dir)\release\GPSBabel.exe" "$($gpsbabel_src_dir)\release\GPSBabel.exe"\r
+if ( "$flow" -ne "cmake" ) {\r
+    Set-Location "$($gpsbabel_src_dir)"\r
+    # make sure we are staring with a clean build directory\r
+    Remove-Item "$($gui_build_dir)" -Recurse -ErrorAction Ignore\r
+    New-Item "$($gui_build_dir)" -type directory -Force | Out-Null\r
+    Set-Location "$($gui_build_dir)"\r
+    switch ($flow) {\r
+        "mingw" { qmake "$($gpsbabel_src_dir)\gui\app.pro" -spec "win32-g++" }\r
+        "msbuild" { qmake -tp vc "$($gpsbabel_src_dir)\gui\app.pro" }\r
+        "nmake" { qmake "$($gpsbabel_src_dir)\gui\app.pro" -spec "win32-msvc" }\r
+    }\r
+    if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) }\r
+    switch ($flow) {\r
+        "mingw" { ming32-make }\r
+        "msbuild" { msbuild GPSBabelFE.vcxproj -property:Configuration=Release -property:Platform=$platform }\r
+        "nmake" { nmake /NOLOGO }\r
+    }\r
+    if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) }\r
 }\r
-if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) }\r
+Set-Location "$($gui_build_dir)"\r
 # work around errors with lupdate, lrelease misprocessing qtHaveModule(webenginewidgets)\r
 # and generating a message to stderr WARNING: Project ERROR: Unknown module(s) in QT: webkit webkitwidgets\r
 # and, on Windows, setting $? to false.\r
@@ -108,6 +113,10 @@ Copy-Item "$($gui_build_dir)\release\GPSBabelFE.exe" "$($gui_build_dir)\package\
 & "$($windeployqt)" --verbose 1 --plugindir package\plugins package\GPSBabelFE.exe package\GPSBabel.exe\r
 if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) }\r
 if ($buildinstaller -eq "true") {\r
+    # set location to location of generated setup.iss file.\r
+    if ( "$flow" -eq "cmake" ) {\r
+        Set-Location "$($gpsbabel_build_dir)/gui"\r
+    }\r
     & "$($iscc)" /Dpackage_dir="$($gui_build_dir)\package" /Dsource_dir="$($gpsbabel_src_dir)\gui" setup.iss\r
     if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) }\r
 }\r